package com.example2016.cjj.materialdesigndemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

public class FruitDetailActivity extends AppCompatActivity {
    public static final String FRUIT_NAME="fruit_name";
    public static final String FRUIT_IMAGEID="fruit_imageid";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fruit_detail);

        Intent startedIntent = getIntent();
        String fruitname = startedIntent.getStringExtra(FRUIT_NAME);
        int fruitimgid = startedIntent.getIntExtra(FRUIT_IMAGEID,0);

        Toolbar toolbar = (Toolbar) findViewById(R.id.fruit_detail_toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if(actionBar!=null){
            actionBar.setDisplayHomeAsUpEnabled(true);
        }

        CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsingToolbar);
        collapsingToolbarLayout.setTitle(fruitname);
        ImageView imageView = (ImageView) findViewById(R.id.iv_fruitImg);
        TextView textView = (TextView) findViewById(R.id.tv_fruitDetails);

        Glide.with(this).load(fruitimgid).into(imageView);
        String fruitDetailStr = generateFruitDetail(fruitname);
        textView.setText(fruitDetailStr);
    }



    private String generateFruitDetail(String fruitname) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i=0;i<=500;i++){
            stringBuilder.append(fruitname);
        }
        return stringBuilder.toString();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
